function e(e, t) {
    e = e.split("."), t = t.split(".");
    for (var a = Math.max(e.length, t.length); e.length < a; ) e.push("0");
    for (;t.length < a; ) t.push("0");
    for (var n = 0; n < a; n++) {
        var r = parseInt(e[n]), s = parseInt(t[n]);
        if (r > s) return 1;
        if (r < s) return -1;
    }
    return 0;
}

function t(e) {
    for (var t = 0; t < e.touches.length; ++t) {
        var a = e.touches[t];
        a.offsetX = a.x, a.offsetY = a.y;
    }
    return e;
}

var a = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e;
} : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
}, n = function(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}(require("./wx-canvas")), r = function(e) {
    if (e && e.__esModule) return e;
    var t = {};
    if (null != e) for (var a in e) Object.prototype.hasOwnProperty.call(e, a) && (t[a] = e[a]);
    return t.default = e, t;
}(require("./echarts")), s = void 0;

Component({
    properties: {
        canvasId: {
            type: String,
            value: "ec-canvas"
        },
        ec: {
            type: Object
        },
        forceUseOldCanvas: {
            type: Boolean,
            value: !1
        }
    },
    data: {
        isUseNewCanvas: !1
    },
    ready: function() {
        r.registerPreprocessor(function(e) {
            e && e.series && (e.series.length > 0 ? e.series.forEach(function(e) {
                e.progressive = 0;
            }) : "object" === a(e.series) && (e.series.progressive = 0));
        }), this.data.ec ? this.data.ec.lazyLoad || this.init() : console.warn('组件需绑定 ec 变量，例：<ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>');
    },
    methods: {
        init: function(t) {
            var a = wx.getSystemInfoSync().SDKVersion, n = e(a, "2.9.0") >= 0, r = this.data.forceUseOldCanvas, s = n && !r;
            if (this.setData({
                isUseNewCanvas: s
            }), r && n && console.warn("开发者强制使用旧canvas,建议关闭"), s) this.initByNewWay(t); else {
                if (!(e(a, "1.9.91") >= 0)) return void console.error("微信基础库版本过低，需大于等于 1.9.91。参见：https://github.com/ecomfe/echarts-for-weixin#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82");
                console.warn("建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能"), this.initByOldWay(t);
            }
        },
        initByOldWay: function(e) {
            var t = this;
            s = wx.createCanvasContext(this.data.canvasId, this);
            var a = new n.default(s, this.data.canvasId, !1);
            r.setCanvasCreator(function() {
                return a;
            });
            wx.createSelectorQuery().in(this).select(".ec-canvas").boundingClientRect(function(n) {
                "function" == typeof e ? t.chart = e(a, n.width, n.height, 1) : t.data.ec && "function" == typeof t.data.ec.onInit ? t.chart = t.data.ec.onInit(a, n.width, n.height, 1) : t.triggerEvent("init", {
                    canvas: a,
                    width: n.width,
                    height: n.height,
                    canvasDpr: 1
                });
            }).exec();
        },
        initByNewWay: function(e) {
            var t = this;
            wx.createSelectorQuery().in(this).select(".ec-canvas").fields({
                node: !0,
                size: !0
            }).exec(function(a) {
                var s = a[0].node;
                t.canvasNode = s;
                var i = wx.getSystemInfoSync().pixelRatio, c = a[0].width, o = a[0].height, h = s.getContext("2d"), u = new n.default(h, t.data.canvasId, !0, s);
                r.setCanvasCreator(function() {
                    return u;
                }), "function" == typeof e ? t.chart = e(u, c, o, i) : t.data.ec && "function" == typeof t.data.ec.onInit ? t.chart = t.data.ec.onInit(u, c, o, i) : t.triggerEvent("init", {
                    canvas: u,
                    width: c,
                    height: o,
                    dpr: i
                });
            });
        },
        canvasToTempFilePath: function(e) {
            var t = this;
            this.data.isUseNewCanvas ? wx.createSelectorQuery().in(this).select(".ec-canvas").fields({
                node: !0,
                size: !0
            }).exec(function(t) {
                var a = t[0].node;
                e.canvas = a, wx.canvasToTempFilePath(e);
            }) : (e.canvasId || (e.canvasId = this.data.canvasId), s.draw(!0, function() {
                wx.canvasToTempFilePath(e, t);
            }));
        },
        touchStart: function(e) {
            if (this.chart && e.touches.length > 0) {
                var a = e.touches[0], n = this.chart.getZr().handler;
                n.dispatch("mousedown", {
                    zrX: a.x,
                    zrY: a.y
                }), n.dispatch("mousemove", {
                    zrX: a.x,
                    zrY: a.y
                }), n.processGesture(t(e), "start");
            }
        },
        touchMove: function(e) {
            if (this.chart && e.touches.length > 0) {
                var a = e.touches[0], n = this.chart.getZr().handler;
                n.dispatch("mousemove", {
                    zrX: a.x,
                    zrY: a.y
                }), n.processGesture(t(e), "change");
            }
        },
        touchEnd: function(e) {
            if (this.chart) {
                var a = e.changedTouches ? e.changedTouches[0] : {}, n = this.chart.getZr().handler;
                n.dispatch("mouseup", {
                    zrX: a.x,
                    zrY: a.y
                }), n.dispatch("click", {
                    zrX: a.x,
                    zrY: a.y
                }), n.processGesture(t(e), "end");
            }
        }
    }
});